<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>$data[name][title] {$this->MAPATH}</title>
    <base href="$baseurl" />
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="static/bootstrap3.3.0/css/bootstrap.min.css">
    <!-- 可选的Bootstrap主题文件（一般不用引入） -->
    <link rel="stylesheet" href="static/bootstrap3.3.0/css/bootstrap-theme.min.css">
    <script src="static/js/jquery-1.12.4.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="static/bootstrap3.3.0/js/bootstrap.min.js"></script>

    <script src="static/jquery-jsonview-master/dist/jquery.jsonview.min.js"></script>
    <link href="static/jquery-jsonview-master/dist/jquery.jsonview.min.css" rel="stylesheet" >

    <script type="text/javascript">

    function responseclient(mode){
      
      var url = '{$APIURL}.'+(mode=='POST'?'toolcp':'toolcg')+'?{$argsurl}';
      $("#responseresult,#responseresulturl,#responseresultcode").html('Loading...');

      $.get(url, function(response){
        responsecode = response;
        try{
          response = JSON.parse(response);
          var d = new Date(response.response_dateline*1000);
          $("#responseresult,#responseresultcode").show();
          $('#responsetitle').html(d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate()+' '+d.getHours()+':'+d.getMinutes()+':'+d.getSeconds()+' / '+mode+' 模拟请求结果 :');
          $("#responseresult").JSONView(response);
          $("#responseresultcode").html(responsecode);
          if (mode == 'GET') {
            $("#responseresulturl").show();
            $("#responseresulturl").html('<a href="{$APIURL}.json?{$argsurl}">{$APIURL}.json?{$argsurl}</a>');
          }else{
            $("#responseresulturl").hide();
          }
          $("#responseresulterror").hide();
        }
        catch(e){
          response = responsecode;
          var d = new Date();

          $('#responsetitle').html(d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate()+' '+d.getHours()+':'+d.getMinutes()+':'+d.getSeconds()+' / '+mode+' 模拟请求结果 : <em style="color:red">( Falid )</em>');
          $("#responseresulterror").show();
          $("#responseresulterror").html(htmlspecialchars(response));
          $("#responseresult,#responseresulturl,#responseresultcode").hide();

        }
      });



    }

    function htmlspecialchars(str) {        
        var s = "";  
        if (str.length == 0) return "";  
        for   (var i=0; i<str.length; i++)  
        {  
            switch (str.substr(i,1))  
            {  
                case "<": s += "&lt;"; break;  
                case ">": s += "&gt;"; break;  
                case "&": s += "&amp;"; break;  
                case " ":  
                    if(str.substr(i + 1, 1) == " "){  
                        s += " &nbsp;";  
                        i++;  
                    } else s += " ";  
                    break;  
                case "\"": s += "&quot;"; break;  
                case "\n": s += "<br>"; break;  
                default: s += str.substr(i,1); break;  
            }  
        }  
        return s;  
    }




    </script>
  </head>
  <body>





  <div class="container">

    <h1>SHOWAPI调试工具</h1>
    <h3>1.当前请求验证</h3>

    <table class="table table-bordered table-striped table-info">
      <caption>参数列表</caption>
      <thead>
        <tr>
          <th width="20%">name</th>
          <th width="70%">value</th>
          <th width="10%"></th>
        </tr>
      </thead>
      <tbody>
        <!--{loop $arguments $key $value}-->
        <tr>
          <td>$key</td>
          <td>$value</td>
           <td><a href="$response_args_url[$key]">x</a></td>
        </tr>
        <!--{/loop}-->
      </tbody>
    </table>



    <h3>2. 构建模拟请求</h3>

    <table class="table table-bordered table-striped table-info" >
      <caption>模拟请求:</caption>
      <thead>
        <tr>
          <th width="20%">name</th>
          <th width="80%">value</th>
        </tr>
      </thead>
      <tbody>
        <!--{loop $response_args $key $value}-->
        <tr>
          <td>$key</td>
          <td>$value</td>
        </tr>
        <!--{/loop}-->
        <tr>
          <td colspan="2" style="word-break: break-all;"><!--{echo htmlspecialchars($_SIGNSTR)}--></td>
        </tr>
        
      </tbody>
    </table>


<p>
  <div class="btn-group btn-group-lg">
    <button type="button" class="btn btn-success" onclick="responseclient('GET')">GET请求模拟</button>
    <button type="button" class="btn btn-info"  onclick="responseclient('POST')">POST请求模拟</button>
  </div>

</p>
<p>

<div class="list-group">
  <p id="responsetitle" class="list-group-item disabled">Result</p>
  <p id="responseresult" class="list-group-item"></p>
  <p id="responseresultcode" class="list-group-item list-group-item-warning"></p>
  <p id="responseresulturl" style="display:none" class="list-group-item list-group-item-warning"></p>
  <p id="responseresulterror" class="list-group-item list-group-item-danger"></p>
</div>


</p>




    </div>
  </body>
</html>